package com.chenyaowei.web.controller.marketing;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenyaowei.common.annotation.Log;
import com.chenyaowei.common.core.controller.BaseController;
import com.chenyaowei.common.core.domain.AjaxResult;
import com.chenyaowei.common.enums.BusinessType;
import com.chenyaowei.marketing.domain.CywSpuFullReduction;
import com.chenyaowei.marketing.service.ICywSpuFullReductionService;
import com.chenyaowei.common.utils.poi.ExcelUtil;
import com.chenyaowei.common.core.page.TableDataInfo;

/**
 * 商品满减Controller
 *
 * @author chenyaowei
 * @date 2023-11-28
 */
@RestController
@RequestMapping("/marketing/spuFullReduction")
public class CywSpuFullReductionController extends BaseController
{
    @Autowired
    private ICywSpuFullReductionService cywSpuFullReductionService;

    /**
     * 查询商品满减列表
     */
    @PreAuthorize("@ss.hasPermi('product:spuFullReduction:list')")
    @GetMapping("/list")
    public TableDataInfo list(CywSpuFullReduction cywSpuFullReduction)
    {
        startPage();
        List<CywSpuFullReduction> list = cywSpuFullReductionService.selectCywSpuFullReductionList(cywSpuFullReduction);
        return getDataTable(list);
    }

    /**
     * 导出商品满减列表
     */
    @PreAuthorize("@ss.hasPermi('product:spuFullReduction:export')")
    @Log(title = "商品满减", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CywSpuFullReduction cywSpuFullReduction)
    {
        List<CywSpuFullReduction> list = cywSpuFullReductionService.selectCywSpuFullReductionList(cywSpuFullReduction);
        ExcelUtil<CywSpuFullReduction> util = new ExcelUtil<CywSpuFullReduction>(CywSpuFullReduction.class);
        util.exportExcel(response, list, "商品满减数据");
    }

    /**
     * 获取商品满减详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:spuFullReduction:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cywSpuFullReductionService.selectCywSpuFullReductionById(id));
    }

    /**
     * 新增商品满减
     */
    @PreAuthorize("@ss.hasPermi('product:spuFullReduction:add')")
    @Log(title = "商品满减", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CywSpuFullReduction cywSpuFullReduction)
    {
        return toAjax(cywSpuFullReductionService.insertCywSpuFullReduction(cywSpuFullReduction));
    }

    /**
     * 修改商品满减
     */
    @PreAuthorize("@ss.hasPermi('product:spuFullReduction:edit')")
    @Log(title = "商品满减", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CywSpuFullReduction cywSpuFullReduction)
    {
        return toAjax(cywSpuFullReductionService.updateCywSpuFullReduction(cywSpuFullReduction));
    }

    /**
     * 删除商品满减
     */
    @PreAuthorize("@ss.hasPermi('product:spuFullReduction:remove')")
    @Log(title = "商品满减", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cywSpuFullReductionService.deleteCywSpuFullReductionByIds(ids));
    }
}
